package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Employee;
import com.itheima.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ping")
@Slf4j
public class PingController {
    @Autowired
    private EmployeeService service;

    @GetMapping
    public R test(@RequestParam Map<String,Object> map){
        String key = (String) map.get("key");
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper();
        wrapper.like(key != null, Employee::getName,key).or()
                .like(key != null, Employee::getPhone,key);

        List<Employee> list = service.list(wrapper);

        log.info("测试连接成功!");
        return R.success(list);
    }
}
